import 'package:enterprise_v6_app/app/components/custom_app_bar.dart';
import 'package:enterprise_v6_app/app/core/core.dart';
import 'package:enterprise_v6_app/app/core/ext/widget_extension.dart';
import 'package:enterprise_v6_app/app/core/utils/interface.dart';
import 'package:enterprise_v6_app/app/data/entities/alarm/all_alarm_records_entity.dart';
import 'package:enterprise_v6_app/router/app_pages.dart';

/// 报警详情-未处置
class NotDispose extends StatefulWidget {
  const NotDispose({super.key});

  @override
  State<NotDispose> createState() => _NotDisposeState();
}

class _NotDisposeState extends State<NotDispose> {

  AllAlarmRecordsEntity item = Get.arguments as AllAlarmRecordsEntity;

  // 去处置
  void toDispose()  {
    Get.toNamed(AppRoutes.undisposedDetailDispose, arguments: item);
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: CustomAppBar(
        titleText: '报警详情',
      ),
      body: Container(
        color: Colors.white,
        child: Column(
          children: [
            Container(
              height: AppDimens.dp12,
              color: AppColors.bg_color_grey,
            ),
            Container(
              height: AppDimens.dp2,
              color: AppColors.blue_button,
            ),
            Container(
              height: AppDimens.dp40,
              width: AppDimens.sw,
              color: const Color(0xFFF4F7FF),
              alignment: Alignment.centerLeft,
              child: Container(margin: EdgeInsets.only(left: AppDimens.dp36), child: Text('报警类型：${item.alarmType}', style: AppTextStyles.black_16)),
            ),
            Expanded(
              child: SingleChildScrollView(
                child: Column(
                  children: [
                    _buildBasicInfoItem('报警等级', item.alarmLevel, false,),
                    _buildBasicInfoItem('报警描述', '${item.alarmContent}', false),
                    _buildBasicInfoItem('报警时间', '${item.alarmTime}', false),
                    _buildBasicInfoItem('设备编号', '${item.numberCode}', false),
                    Container(
                      padding: EdgeInsets.symmetric(horizontal: 38.w, vertical: 6.w),
                      alignment: Alignment.centerLeft,
                      child: Text(
                        '图片',
                        style: TextStyle(
                          fontSize: 14.sp,
                          color: const Color(0xFF7C7D93),
                        ),
                      ),
                    ),
                    Container(
                      margin: EdgeInsets.symmetric(horizontal: 37.w, vertical: 6.w),
                      alignment: Alignment.centerLeft,
                      child: item.filePath != '' ? Wrap(
                        spacing: 10.w,
                        runSpacing: 10.w,
                        children: item.filePath.split(',').map(_buildPicItem).toList(),
                      ) : Container(
                        height: 77.w,
                        width: 77.w,
                        alignment: Alignment.center,
                        decoration: BoxDecoration(
                          color: AppColors.bg_color_grey,
                          borderRadius: BorderRadius.circular(8),
                        ),
                        child: Text('暂无图片',style: TextStyle(
                          fontSize: 12.sp,
                          color: const Color(0xFF7C7D93),
                        ),),
                      ),
                    ),
                    AppGaps.vGap28,
                  ],
                ),
              ),
            ),
          ],
        ),
      ),
      bottomSheet: Container(
        height: 48.w,
        width: AppDimens.sw,
        color: AppColors.blue_button,
        alignment: Alignment.center,
        child: Text('处置',style: TextStyle(
          fontSize: 16.sp,
          color: Colors.white,
        )),
      ).clickOnce(toDispose),
    );
  }

  /// 基本信息
  Widget _buildBasicInfoItem(String key, String val, bool isRequired, {double? width,Color? fontColor}) {
    return Padding(
      padding: EdgeInsets.symmetric(horizontal: 37.w, vertical: 6.w),
      child: Row(
        children: [
          SizedBox(
            width: width ?? 120.w,
            child: Row(
              mainAxisAlignment: MainAxisAlignment.start,
              children: [
                if (isRequired)
                  Text(
                    '*',
                    style: TextStyle(
                      fontSize: 13.sp,
                      color: Colors.red,
                    ),
                    textAlign: TextAlign.center,
                  ),
                Text(
                  key,
                  style: TextStyle(
                    fontSize: 14.sp,
                    color: const Color(0xFF7C7D93),
                  ),
                )
              ],
            ),
          ),
          Expanded(
            child: Text(
              val,
              style: TextStyle(
                fontSize: 12.sp,
                color: fontColor ?? const Color(0xFF495061),
              ),
            ),
          ),
        ],
      ),
    );
  }

  Widget _buildPicItem(String url) {
    return ClipRRect(
      borderRadius: BorderRadius.circular(8),
      child: SizedBox(
        height: 77.w,
        width: 77.w,
        child: Image.network(
          url.startsWith('http') ? url : Interface.fileUrl + url ,
          fit: BoxFit.cover,),
      ),
    ).clickShowLarge(
      url:  url.startsWith('http') ? url : Interface.fileUrl + url ,
    );
  }

}
